class Balance
  cattr_accessor :cache
  attr_accessor :total, :balance_items
  
  def initialize(cache = true)
    self.balance_items = Array.new
    
    User.find(:all).each do |user|
      user_balance = user.balance
      
      self.total += user_balance.to_f
      balance_item = BalanceItem.new :user => user, :balance => user_balance
      self.balance_items << balance_item
      
      #Als de user niet meer actief is, wel meenemen in de berekeningen, maar niet meer laten ZIEN!
      self.balance_items.delete_if {|bi| not bi.user.active? }
      
    end
    return balance_items
  end
  
  def total
    @total || 0.to_f
  end
  
end